home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / EasyPHP-2.0b1-setup.exe / {app} / phpmyadmin / tbl_printview.php < prev    next >
Encoding:
PHP Script  |  2006-11-18  |  17.9 KB  |  553 lines

  1. <?php
  2. /* $Id: tbl_printview.php 9202 2006-07-27 17:14:30Z lem9 $ */
  3.  
  4. require_once './libraries/common.lib.php';
  5.  
  6. require './libraries/tbl_properties_common.php';
  7.  
  8. /**
  9.  * Gets the variables sent or posted to this script, then displays headers
  10.  */
  11. $print_view = true;
  12. if (! isset($selected_tbl)) {
  13.     require_once './libraries/header.inc.php';
  14. }
  15.  
  16. // Check parameters
  17.  
  18. if (! isset($the_tables) || ! is_array($the_tables)) {
  19.     $the_tables = array();
  20. }
  21.  
  22. /**
  23.  * Gets the relations settings
  24.  */
  25. require_once './libraries/relation.lib.php';
  26. require_once './libraries/transformations.lib.php';
  27. require_once './libraries/tbl_indexes.lib.php';
  28.  
  29. $cfgRelation = PMA_getRelationsParam();
  30.  
  31. /**
  32.  * Defines the url to return to in case of error in a sql statement
  33.  */
  34. if (isset($table)) {
  35.     $err_url = 'tbl_properties.php?' . PMA_generate_common_url($db, $table);
  36. } else {
  37.     $err_url = 'db_details.php?' . PMA_generate_common_url($db);
  38. }
  39.  
  40.  
  41. /**
  42.  * Selects the database
  43.  */
  44. PMA_DBI_select_db($db);
  45.  
  46.  
  47. /**
  48.  * Multi-tables printview thanks to Christophe Gesche from the "MySQL Form
  49.  * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/)
  50.  */
  51. if (isset($selected_tbl) && is_array($selected_tbl)) {
  52.     $the_tables   = $selected_tbl;
  53. } elseif (isset($table)) {
  54.     $the_tables[] = $table;
  55. }
  56. $multi_tables     = (count($the_tables) > 1);
  57.  
  58. if ($multi_tables) {
  59.     if (empty($GLOBALS['is_header_sent'])) {
  60.         require_once './libraries/header.inc.php';
  61.     }
  62.     $tbl_list     = '';
  63.     foreach ($the_tables as $key => $table) {
  64.         $tbl_list .= (empty($tbl_list) ? '' : ', ')
  65.                   . PMA_backquote(urldecode($table));
  66.     }
  67.     echo '<b>'.  $strShowTables . ': ' . $tbl_list . '</b>' . "\n";
  68.     echo '<hr />' . "\n";
  69. } // end if
  70.  
  71. $tables_cnt = count($the_tables);
  72. $counter    = 0;
  73.  
  74. foreach ($the_tables as $key => $table) {
  75.     $table = urldecode($table);
  76.     if ($counter + 1 >= $tables_cnt) {
  77.         $breakstyle = '';
  78.     } else {
  79.         $breakstyle = ' style="page-break-after: always;"';
  80.     }
  81.     $counter++;
  82.     echo '<div' . $breakstyle . '>' . "\n";
  83.     echo '<h1>' . $table . '</h1>' . "\n";
  84.  
  85.     /**
  86.      * Gets table informations
  87.      */
  88.     $result       = PMA_DBI_query(
  89.         'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, true) . '\';');
  90.     $showtable    = PMA_DBI_fetch_assoc($result);
  91.     $num_rows     = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
  92.     $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
  93.     PMA_DBI_free_result($result);
  94.  
  95.     $tbl_is_view = PMA_Table::isView($db, $table);
  96.  
  97.     //  Gets table keys and store them in arrays
  98.     $indexes      = array();
  99.     $indexes_info = array();
  100.     $indexes_data = array();
  101.     $ret_keys = PMA_get_indexes($table, $err_url_0);
  102.  
  103.     PMA_extract_indexes($ret_keys, $indexes, $indexes_info, $indexes_data);
  104.  
  105.     /**
  106.      * Gets fields properties
  107.      */
  108.     $result      = PMA_DBI_query(
  109.         'SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null,
  110.         PMA_DBI_QUERY_STORE);
  111.     $fields_cnt  = PMA_DBI_num_rows($result);
  112.  
  113.     
  114. // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
  115. // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
  116. // and SHOW CREATE TABLE says NOT NULL (tested
  117. // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
  118.  
  119.     $show_create_table = PMA_DBI_fetch_value(
  120.         'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
  121.         0, 1);
  122.     $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
  123.  
  124.     // Check if we can use Relations (Mike Beck)
  125.     if (!empty($cfgRelation['relation'])) {
  126.         // Find which tables are related with the current one and write it in
  127.         // an array
  128.         $res_rel = PMA_getForeigners($db, $table);
  129.  
  130.         if (count($res_rel) > 0) {
  131.             $have_rel = true;
  132.         } else {
  133.             $have_rel = false;
  134.         }
  135.     } else {
  136.            $have_rel = false;
  137.     } // end if
  138.  
  139.  
  140.     /**
  141.      * Displays the comments of the table if MySQL >= 3.23
  142.      */
  143.     if (!empty($show_comment)) {
  144.         echo $strTableComments . ': ' . $show_comment . '<br /><br />';
  145.     }
  146.  
  147.     /**
  148.      * Displays the table structure
  149.      */
  150.     ?>
  151.  
  152. <!-- TABLE INFORMATIONS -->
  153. <table style="width: 100%;">
  154. <thead>
  155. <tr>
  156.     <th><?php echo $strField; ?></th>
  157.     <th><?php echo $strType; ?></th>
  158.     <!--<th><?php echo $strAttr; ?></th>-->
  159.     <th><?php echo $strNull; ?></th>
  160.     <th><?php echo $strDefault; ?></th>
  161.     <!--<th><?php echo $strExtra; ?></th>-->
  162.     <?php
  163.     if ($have_rel) {
  164.         echo '<th>' . $strLinksTo . '</th>' . "\n";
  165.     }
  166.     if ($cfgRelation['commwork']) {
  167.         echo '    <th>' . $strComments . '</th>' . "\n";
  168.     }
  169.     if ($cfgRelation['mimework']) {
  170.         echo '    <th>MIME</th>' . "\n";
  171.     }
  172.     ?>
  173. </tr>
  174. </thead>
  175. <tbody>
  176.     <?php
  177.     while ($row = PMA_DBI_fetch_assoc($result)) {
  178.         $type             = $row['Type'];
  179.         // reformat mysql query output - staybyte - 9. June 2001
  180.         // loic1: set or enum types: slashes single quotes inside options
  181.         if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
  182.             $tmp[2]       = substr(preg_replace('@([^,])\'\'@', '\\1\\\'',
  183.                                     ',' . $tmp[2]), 1);
  184.             $type         = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
  185.  
  186.             $binary       = 0;
  187.             $unsigned     = 0;
  188.             $zerofill     = 0;
  189.         } else {
  190.             $type         = preg_replace('@BINARY@i', '', $type);
  191.             $type         = preg_replace('@ZEROFILL@i', '', $type);
  192.             $type         = preg_replace('@UNSIGNED@i', '', $type);
  193.             if (empty($type)) {
  194.                 $type     = ' ';
  195.             }
  196.  
  197.             $binary       = stristr($row['Type'], 'binary');
  198.             $unsigned     = stristr($row['Type'], 'unsigned');
  199.             $zerofill     = stristr($row['Type'], 'zerofill');
  200.         }
  201.         $strAttribute     = ' ';
  202.         if ($binary) {
  203.             $strAttribute = 'BINARY';
  204.         }
  205.         if ($unsigned) {
  206.             $strAttribute = 'UNSIGNED';
  207.         }
  208.         if ($zerofill) {
  209.             $strAttribute = 'UNSIGNED ZEROFILL';
  210.         }
  211.         if (!isset($row['Default'])) {
  212.             if ($row['Null'] != ''  && $row['Null'] != 'NO') {
  213.                 $row['Default'] = '<i>NULL</i>';
  214.             }
  215.         } else {
  216.             $row['Default'] = htmlspecialchars($row['Default']);
  217.         }
  218.         $field_name = htmlspecialchars($row['Field']);
  219.  
  220.         // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
  221.         // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
  222.         // the latter.
  223.     // TODO: merge this logic with the one in tbl_properties_structure.php
  224.     // or move it in a function similar to PMA_DBI_get_columns_full()
  225.     // but based on SHOW CREATE TABLE because information_schema
  226.     // cannot be trusted in this case (MySQL bug)
  227.         if (!empty($analyzed_sql[0]['create_table_fields'][$field_name]['type']) && $analyzed_sql[0]['create_table_fields'][$field_name]['type'] == 'TIMESTAMP' && $analyzed_sql[0]['create_table_fields'][$field_name]['timestamp_not_null']) {
  228.             $row['Null'] = '';
  229.         }
  230.         ?>
  231.  
  232. <tr><td>
  233.     <?php
  234.     if (isset($pk_array[$row['Field']])) {
  235.         echo '    <u>' . $field_name . '</u>' . "\n";
  236.     } else {
  237.         echo '    ' . $field_name . "\n";
  238.     }
  239.     ?>
  240.     </td>
  241.     <td><?php echo $type; ?><bdo dir="ltr"></bdo></td>
  242.     <!--<td><?php echo $strAttribute; ?></td>-->
  243.     <td><?php echo (($row['Null'] == '' || $row['Null'] == 'NO') ? $strNo : $strYes); ?> </td>
  244.     <td><?php if (isset($row['Default'])) { echo $row['Default']; } ?> </td>
  245.     <!--<td><?php echo $row['Extra']; ?> </td>-->
  246.     <?php
  247.     if ($have_rel) {
  248.         echo '    <td>';
  249.         if (isset($res_rel[$field_name])) {
  250.             echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] );
  251.         }
  252.         echo ' </td>' . "\n";
  253.     }
  254.     if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
  255.         echo '    <td>';
  256.         $comments = PMA_getComments($db, $table);
  257.         if (isset($comments[$field_name])) {
  258.             echo htmlspecialchars($comments[$field_name]);
  259.         }
  260.         echo ' </td>' . "\n";
  261.     }
  262.     if ($cfgRelation['mimework']) {
  263.         $mime_map = PMA_getMIME($db, $table, true);
  264.  
  265.         echo '    <td>';
  266.         if (isset($mime_map[$field_name])) {
  267.             echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
  268.         }
  269.         echo ' </td>' . "\n";
  270.     }
  271.     ?>
  272. </tr>
  273.         <?php
  274.     } // end while
  275.     PMA_DBI_free_result($result);
  276.     ?>
  277. </tbody>
  278. </table>
  279.  
  280.     <?php
  281.  
  282.     if ( ! $tbl_is_view
  283.       && ( $db != 'information_schema'
  284.         || PMA_MYSQL_INT_VERSION < 50002 ) ) {
  285.  
  286.         /**
  287.          * Displays indexes
  288.          */
  289.         $index_count = (isset($indexes))
  290.                      ? count($indexes)
  291.                      : 0;
  292.         if ($index_count > 0) {
  293.             echo "\n";
  294.             ?>
  295.     <br /><br />
  296.  
  297.     <!-- Indexes -->
  298.     <big><?php echo $strIndexes . ':'; ?></big>
  299.     <table>
  300.         <tr>
  301.             <th><?php echo $strKeyname; ?></th>
  302.             <th><?php echo $strType; ?></th>
  303.             <th><?php echo $strCardinality; ?></th>
  304.             <th colspan="2"><?php echo $strField; ?></th>
  305.         </tr>
  306.             <?php
  307.             echo "\n";
  308.             PMA_show_indexes($table, $indexes, $indexes_info, $indexes_data, true, true);
  309.             echo "\n";
  310.             ?>
  311.     </table>
  312.             <?php
  313.             echo "\n";
  314.         } // end display indexes
  315.  
  316.  
  317.         /**
  318.          * Displays Space usage and row statistics
  319.          *
  320.          * staybyte - 9 June 2001
  321.          */
  322.         if ($cfg['ShowStats']) {
  323.             $nonisam     = false;
  324.             if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
  325.                 $nonisam = true;
  326.             }
  327.             if ($nonisam == false) {
  328.                 // Gets some sizes
  329.                 $mergetable     = false;
  330.                 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
  331.                     $mergetable = true;
  332.                 }
  333.                 list($data_size, $data_unit)         = PMA_formatByteDown($showtable['Data_length']);
  334.                 if ($mergetable == false) {
  335.                     list($index_size, $index_unit)   = PMA_formatByteDown($showtable['Index_length']);
  336.                 }
  337.                 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
  338.                     list($free_size, $free_unit)     = PMA_formatByteDown($showtable['Data_free']);
  339.                     list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
  340.                 } else {
  341.                     unset($free_size);
  342.                     unset($free_unit);
  343.                     list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
  344.                 }
  345.                 list($tot_size, $tot_unit)           = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
  346.                 if ($num_rows > 0) {
  347.                     list($avg_size, $avg_unit)       = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
  348.                 }
  349.  
  350.                 // Displays them
  351.                 ?>
  352.     <br /><br />
  353.  
  354.     <table border="0" cellspacing="0" cellpadding="0" class="noborder">
  355.     <tr>
  356.  
  357.         <!-- Space usage -->
  358.         <td valign="top">
  359.             <big><?php echo $strSpaceUsage . ':'; ?></big>
  360.             <table width="100%">
  361.             <tr>
  362.                 <th><?php echo $strType; ?></th>
  363.                 <th colspan="2" align="center"><?php echo $strUsage; ?></th>
  364.             </tr>
  365.             <tr>
  366.                 <td style="padding-right: 10px"><?php echo $strData; ?></td>
  367.                 <td align="right"><?php echo $data_size; ?></td>
  368.                 <td><?php echo $data_unit; ?></td>
  369.             </tr>
  370.                 <?php
  371.                 if (isset($index_size)) {
  372.                     echo "\n";
  373.                     ?>
  374.             <tr>
  375.                 <td style="padding-right: 10px"><?php echo $strIndex; ?></td>
  376.                 <td align="right"><?php echo $index_size; ?></td>
  377.                 <td><?php echo $index_unit; ?></td>
  378.             </tr>
  379.                     <?php
  380.                 }
  381.                 if (isset($free_size)) {
  382.                     echo "\n";
  383.                     ?>
  384.             <tr style="color: #bb0000">
  385.                 <td style="padding-right: 10px"><?php echo $strOverhead; ?></td>
  386.                 <td align="right"><?php echo $free_size; ?></td>
  387.                 <td><?php echo $free_unit; ?></td>
  388.             </tr>
  389.             <tr>
  390.                 <td style="padding-right: 10px"><?php echo $strEffective; ?></td>
  391.                 <td align="right"><?php echo $effect_size; ?></td>
  392.                 <td><?php echo $effect_unit; ?></td>
  393.             </tr>
  394.                     <?php
  395.                 }
  396.                 if (isset($tot_size) && $mergetable == false) {
  397.                     echo "\n";
  398.                     ?>
  399.             <tr>
  400.                 <td style="padding-right: 10px"><?php echo $strTotalUC; ?></td>
  401.                 <td align="right"><?php echo $tot_size; ?></td>
  402.                 <td><?php echo $tot_unit; ?></td>
  403.             </tr>
  404.                     <?php
  405.                 }
  406.                 echo "\n";
  407.                 ?>
  408.             </table>
  409.         </td>
  410.  
  411.         <td width="20"> </td>
  412.  
  413.         <!-- Rows Statistic -->
  414.         <td valign="top">
  415.             <big><?php echo $strRowsStatistic . ':'; ?></big>
  416.             <table width="100%">
  417.             <tr>
  418.                 <th><?php echo $strStatement; ?></th>
  419.                 <th align="center"><?php echo $strValue; ?></th>
  420.             </tr>
  421.                 <?php
  422.                 if (isset($showtable['Row_format'])) {
  423.                     ?>
  424.             <tr>
  425.                 <td><?php echo ucfirst($strFormat); ?></td>
  426.                 <td align="<?php echo $cell_align_left; ?>">
  427.                     <?php
  428.                     if ($showtable['Row_format'] == 'Fixed') {
  429.                         echo $strFixed;
  430.                     } elseif ($showtable['Row_format'] == 'Dynamic') {
  431.                         echo $strDynamic;
  432.                     } else {
  433.                         echo $showtable['Row_format'];
  434.                     }
  435.                     ?>
  436.                 </td>
  437.             </tr>
  438.                     <?php
  439.                 }
  440.                 if (isset($showtable['Rows'])) {
  441.                     ?>
  442.             <tr>
  443.                 <td><?php echo ucfirst($strRows); ?></td>
  444.                 <td align="right">
  445.                     <?php echo number_format($showtable['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
  446.                 </td>
  447.             </tr>
  448.                     <?php
  449.                 }
  450.                 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
  451.                     ?>
  452.             <tr>
  453.                 <td><?php echo ucfirst($strRowLength); ?> ø</td>
  454.                 <td>
  455.                     <?php echo number_format($showtable['Avg_row_length'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
  456.                 </td>
  457.             </tr>
  458.                     <?php
  459.                 }
  460.                 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
  461.                     ?>
  462.             <tr>
  463.                 <td><?php echo ucfirst($strRowSize); ?> ø</td>
  464.                 <td align="right">
  465.                     <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
  466.                 </td>
  467.             </tr>
  468.                     <?php
  469.                 }
  470.                 if (isset($showtable['Auto_increment'])) {
  471.                     ?>
  472.             <tr>
  473.                 <td><?php echo ucfirst($strNext); ?> Autoindex</td>
  474.                 <td align="right">
  475.                     <?php echo number_format($showtable['Auto_increment'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
  476.                 </td>
  477.             </tr>
  478.                     <?php
  479.                 }
  480.                 if (isset($showtable['Create_time'])) {
  481.                     ?>
  482.             <tr>
  483.                 <td><?php echo $strStatCreateTime; ?></td>
  484.                 <td align="right">
  485.                     <?php echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?>
  486.                 </td>
  487.             </tr>
  488.                     <?php
  489.                 }
  490.                 if (isset($showtable['Update_time'])) {
  491.                     ?>
  492.             <tr>
  493.                 <td><?php echo $strStatUpdateTime; ?></td>
  494.                 <td align="right">
  495.                     <?php echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?>
  496.                 </td>
  497.             </tr>
  498.                     <?php
  499.                 }
  500.                 if (isset($showtable['Check_time'])) {
  501.                     ?>
  502.             <tr>
  503.                 <td><?php echo $strStatCheckTime; ?></td>
  504.                 <td align="right">
  505.                     <?php echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?>
  506.                 </td>
  507.             </tr>
  508.                     <?php
  509.                 }
  510.                 ?>
  511.  
  512.             </table>
  513.         </td>
  514.     </tr>
  515.     </table>
  516.  
  517.                 <?php
  518.             } // end if ($nonisam == false)
  519.         } // end if ($cfg['ShowStats'])
  520.     }
  521.     if ($multi_tables) {
  522.         unset($ret_keys, $num_rows, $show_comment);
  523.         echo '<hr />' . "\n";
  524.     } // end if
  525.     echo '</div>' . "\n";
  526.  
  527. } // end while
  528.  
  529. /**
  530.  * Displays the footer
  531.  */
  532. ?>
  533.  
  534. <script type="text/javascript" language="javascript">
  535. //<![CDATA[
  536. function printPage()
  537. {
  538.     // Do print the page
  539.     if (typeof(window.print) != 'undefined') {
  540.         window.print();
  541.     }
  542. }
  543. //]]>
  544. </script>
  545.  
  546. <p class="print_ignore">
  547.     <input type="button" id="print" value="<?php echo $strPrint; ?>"
  548.         onclick="printPage()" /></p>
  549.  
  550. <?php
  551. require_once './libraries/footer.inc.php';
  552. ?>
  553.